using System.Configuration;
using System.IO;
using System.Xml;
using System.Xml.XPath;

namespace CriticalSystems.Instrumentation.Configuration
{
    /// <summary>
    /// A configuration element that contains arbitrary XML.
    /// </summary>
    public class ArbitraryElement : ConfigurationElement
    {
        private IXPathNavigable innerXml;

        /// <summary>
        /// Gets the inner XML.
        /// </summary>
        /// <value>The inner XML.</value>
        public IXPathNavigable InnerXml
        {
            get { return this.innerXml; }
        }

        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            if (!serializeCollectionKey)
            {
                string xml = reader.ReadOuterXml();
                this.innerXml = new XPathDocument(new StringReader(xml));
            }
            else
            {
                reader.ReadEndElement();
            }

            PostDeserialize();
        }
    }
}